package com.ciaojian.client.controller;

import com.ciaojian.client.model.param.ProtocolAgreeDTO;
import com.ciaojian.client.service.ProtocolServiceImpl;
import com.ciaojian.client.service.ProtocolUserRecordServiceImpl;
import com.ciaojian.core.model.ProtocolUserRecord;
import com.ciaojian.core.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @author oxiny
 */
@Api(tags = "协议模块")
@Validated
@RestController
@RequestMapping("/protocol")
public class ProtocolController {
    @Resource
    private ProtocolServiceImpl protocolService;
    @Resource
    private ProtocolUserRecordServiceImpl protocolUserRecordService;

    @ApiOperation("显示未同意的协议")
    @GetMapping("/show")
    public Result showProtocol(@NotNull Integer storeId, @NotNull Integer userId) {
        return Result.ok(protocolService.showForUser(storeId, userId));
    }

    @ApiOperation("同意协议")
    @PostMapping("/agree")
    public Result agreeProtocol(@Validated @RequestBody ProtocolAgreeDTO data) {
        ProtocolUserRecord record = data.convert();
        protocolUserRecordService.agree(record);
        return Result.ok();
    }
}






